package qq

import (
	"api-go/serializer"
	"api-go/util"
	"strconv"
)

// MV所需信息
type MV struct {
	Offset string `form:"offset"`
	Id     string `form:"id"`
	Limit  string `form:"limit"`
}

//获取MV列表
func (service *MV) MVList() *serializer.Response {

	if val := service.Offset; val != "" {
		service.Offset = val
	} else {
		service.Offset = "1"
	}

	if val := service.Limit; val != "" {
		service.Limit = val
	} else {
		service.Limit = "30"
	}

	newLimit, _ := strconv.ParseInt(service.Limit, 10, 64)
	newOffset, _ := strconv.ParseInt(service.Offset, 10, 64)
	page := newLimit * (newOffset - 1)

	url := "https://u.y.qq.com/cgi-bin/musicu.fcg?data={\"comm\":{\"ct\":24},\"mv_list\":{\"module\":\"MvService.MvInfoProServer\",\"method\":\"GetAllocMvInfo\",\"param\":{\"start\":" + strconv.FormatInt(page, 10) + ",\"size\":" + service.Limit + ",\"version_id\":8,\"area_id\":15,\"order\":1}}}"

	res, err := util.Get(url)
	if err != nil {
		return err
	}
	return serializer.OkResponse(res)
}

//获取MV信息
func (service *MV) MVInfo() *serializer.Response {

	//此处Id实则为hash
	if val := service.Id; val != "" {
		service.Id = val
	} else {
		service.Id = "u00428itsi5"
	}

	url := "https://u.y.qq.com/cgi-bin/musicu.fcg?data={\"getMvUrl\":{\"module\":\"gosrf.Stream.MvUrlProxy\",\"method\":\"GetMvUrls\",\"param\":{\"vids\":[\"" + service.Id + "\"],\"request_typet\":10001}}}"

	res, err := util.Get(url)
	if err != nil {
		return err
	}
	return serializer.OkResponse(res)
}
